﻿//-----------------------------------------------------------------------
// <summary>
//  The file contains a class that used to treat style cop settings 
// </summary>
// <copyright file="PropertyRIBootstrapper.cs" company="DSSoftLogic">
//     Copyright@ DSSoftLogic 2011, Non-Commercial. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace Property
{
    using System;
    using System.ComponentModel.Composition.Hosting;
    using System.Windows;
    using Microsoft.Practices.Prism.MefExtensions;
    using Microsoft.Practices.Prism.Modularity;
    using Microsoft.Practices.Prism.Regions;
    using Property.Silverlight.Infrastructure;
    using Property.Silverlight.Module;

    /// <summary>
    /// This Bootstrapper is testing the StyleCop rules and how to use them.
    /// </summary>
    [CLSCompliant(false)]
    public class PropertyRIBootstrapper : MefBootstrapper
    {
        /// <summary>
        /// Callbacklogger will back the application log file
        /// </summary>
        private readonly CallbackLogger callbackLogger = new CallbackLogger();

        /// <summary>
        /// ConfigureAggregateCatalog method has directly reference to all Module
        /// </summary>
        protected override void ConfigureAggregateCatalog()
        {
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewExportAttribute).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PropertyRIBootstrapper).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(PropertyModule).Assembly));
        }

        /// <summary>
        /// Creates the <see cref="IModuleCatalog"/> used by Prism.
        /// </summary>
        /// <remarks>
        /// The base implementation returns a new ModuleCatalog.
        /// </remarks>
        /// <returns>
        /// A ConfigurationModuleCatalog.
        /// </returns>
        ////protected override IModuleCatalog CreateModuleCatalog()
        ////{
        ////    return base.CreateModuleCatalog();
        ////}

        /// <summary>
        /// Override the is InitializeShell 
        /// </summary>
        protected override void InitializeShell()
        {
            base.InitializeShell();
            Application.Current.RootVisual = (ShellView)this.Shell;
        }

        /// <summary>
        /// This is method CreateShell
        /// </summary>
        /// <returns>shell view</returns>
        protected override DependencyObject CreateShell()
        {
            return this.Container.GetExportedValue<ShellView>();
        }

        /// <summary>
        /// ConfigureDefaultRegionBehaviors method
        /// </summary>
        /// <returns>returns factory</returns>
        protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
        {
            var factory = base.ConfigureDefaultRegionBehaviors();

            // Behavior that registers all views decorated with the ViewExport attribute
            factory.AddIfMissing("AutoPopulateExportedViewsBehavior", typeof(AutoPopulateExportedViewsBehavior));
            return factory;
        }

        /// <summary>
        /// This is ConfigureModuleCatalog should simply call the all Modules to load it is also use as Module Controller
        /// </summary>
        ////protected override void ConfigureModuleCatalog()
        ////{
        ////    base.ConfigureModuleCatalog();
        ////    ////The ModuleCatalog class is used to define the application's modules from code
        ////    ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog;
        ////    moduleCatalog.AddModule(typeof(PropertyModule));
        ////}
    }
}
